﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetLastInformationList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            LastInformationOutParam result = new LastInformationOutParam();
            LastInformationInParam param = new LastInformationInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as LastInformationInParam; 

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetLastInformationList();

                    LastInformation itemTemp; 
                    //for (int i = 1; i < 8; i++)
                    for (int i = 1; i < 5; i++) // 精简了2，3， 19三种类型
                    {
                        itemTemp = new LastInformation();
                        if (ds != null && ds.Tables.Count >= i)
                        {
                            if (ds.Tables[i - 1].Rows.Count > 0)
                            {
                                if (ds.Tables[i - 1].Rows[0]["type"].ToString() != "5")
                                {
                                    itemTemp.info_time = ds.Tables[i - 1].Rows[0]["publish_time"].ToString();
                                    itemTemp.info_title = ds.Tables[i - 1].Rows[0]["title"].ToString();
                                    itemTemp.info_type = ds.Tables[i - 1].Rows[0]["type"].ToString();
                                }
                                else
                                {

                                    //DataTable dsB = InterfaceHelper.QueryNews("D658070EC3BF425BA8417745FDCBFCB0", 1, 1);
                                    //if (dsB != null && dsB.Rows.Count > 0)
                                    //{
                                    //    itemTemp.info_time = dsB.Rows[0]["publish_time"].ToString();
                                    //    itemTemp.info_title = dsB.Rows[0]["title"].ToString();
                                    //    itemTemp.info_type = "5";
                                    //}
                                }
                            }
                        }
                        result.data.list.Add(itemTemp);
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetLastInformationList", SerializeHelper.JsonSerializer<LastInformationInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<LastInformationInParam, LastInformationOutParam>();
            else
                SafeProcessRequest<LastInformationInParam, LastInformationOutParam>();
        }
    }

    #region 请求参数
    public class LastInformationInParam
    { 
    }
    #endregion

    #region 结果参数
    public class LastInformationOutParam
    {
        public LastInformationOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LastInformationList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 资讯列表
        /// </summary>
        public LastInformationList data
        { get; set; }
    }

    public class LastInformationList
    {
        public LastInformationList()
        { 
            list = new List<LastInformation>();
        }

        public List<LastInformation> list { get; set; } 
    }
     
    /// <summary>
    /// 资讯列表
    /// </summary>
    public class LastInformation
    {
        /// <summary>
        ///	资讯类别  1：通知公告3：学习十八大  4：党员先锋 5:组织风采 6:干部工作 7 人才天地
        /// </summary>
        public string info_type
        { get; set; }

        /// <summary>
        ///	最新资讯标题
        /// </summary>
        public string info_title
        { get; set; }

        /// <summary>
        ///	最新资讯时间
        /// </summary>
        public string info_time
        { get; set; } 
    }
    #endregion 
}